#include <iostream>

using namespace std;

int main()
{
    int n;
    while (cin >> n)
    {
        if (!n)
        {
            break;
        }
        int count = 0;
        int empty = n;
        while (empty / 3)
        {
            count += empty / 3;
            empty = empty / 3 + empty % 3;
        }
        if (empty == 2)
        {
            ++count;
        }
        printf("%d\n", count);
    }
    return 0;
}